#include <iostream>
#include <vector>

using namespace std;
class Solution
{
public:
   int minMaxGame(vector<int> &nums)
   {
      int n = nums.size();
      while (n > 1)
      {
         vector<int> newNums(n / 2);
         for (int i = 0; i < n / 2; i++)
         {
            newNums[i] = (i % 2 == 0) ? min(nums[2 * i], nums[2 * i + 1]) : max(nums[2 * i], nums[2 * i + 1]);
         }
         //nums.assign(newNums.begin(), newNums.end());
         nums = move(newNums);
         for (int n : nums)
         {
            cout << n << " ";
         }
         cout << endl;
         n = nums.size();
      }

      return nums[0];
   }
};
int main()
{
   Solution s;
   vector<int> nums = {1, 3, 5, 2, 4, 8, 2, 2};
   cout << s.minMaxGame(nums) << endl;
   system("pause");
   return 0;
}
